'''
An RPG Modification for Source games using Source Python.

    Copyright (C) 2012 Steven Hartin

    This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program.  If not, see <http://www.gnu.org/licenses/>.

Created on 4 Dec 2012

@author: Steven Hartin
@file: ../sourcerpg/utils/baseclass.py
'''

from sourcerpg.logging import auto_logger

__all__ = ["BaseClass"]


class BaseClass(object):
    """Base class to automatically set up default behaviour for all classes

    For the moment, the only thing this base class should do is set up the
    auto hooking for all classes. Rather than manually setting it up for each
    class, this should do it the first time a class is instantiated.

    """

    def __new__(cls, *args, **kwargs):
        # Python 3.0 changed it so __new__ accepts NO arguments... *sigh*
        # http://freshfoo.com/blog/object__init__takes_no_parameters
        #instance = super(BaseClass, cls).__new__(cls, *args, **kwargs)
        instance = super(BaseClass, cls).__new__(cls)

        if not hasattr(cls, "__hooked_already"):
            auto_logger.hook_all_functions_for_class(cls)
            cls.__hooked_already = True

        return instance
